package com.bird.user.domain.vo

import cn.hutool.core.util.PhoneUtil
import com.bird.component.lang.util.paramcheck.toCheck
import com.bird.component.lang.util.saltMd5

/**
 * 用户密码
 */
data class UserPassword(
    val password: String
) {
    companion object {
        fun create(originPassword: String, salt: String): UserPassword {
            return UserPassword(originPassword.saltMd5(salt))
        }
    }

    fun checkPassword(password: String, salt: String): Boolean {
        return password.saltMd5(salt) == this.password
    }
}


data class Phone(
    val phone:String
){
    init {
        toCheck {
            customize(phone){ PhoneUtil.isPhone(it)}.orTip("手机号格式不正确")
        }
    }
}

data class Nickname(
    val nickname: String
){
    init {
        toCheck {
            customize(nickname){nickname.length in 1 .. 10 }.orTip("昵称长度要小于10且不能是空的")
        }
    }
}